package com.bonc.modules.job.task;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bonc.common.utils.SignUtil;
import com.bonc.common.utils.SupermanUtil;
import com.bonc.datasource.annotation.DataSource;
import com.bonc.modules.business.entity.TbWorkOederDistributionEntity;
import com.bonc.modules.business.entity.TbWorkOrderReplyEntity;
import com.bonc.modules.business.service.FileSystemService;
import com.bonc.modules.business.service.TbWorkOederDistributionService;
import com.bonc.modules.business.service.TbWorkOrderReplyService;
import com.bonc.modules.sys.entity.SysUserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.locks.Lock;

/**
 * 工单回复 省——集团 定时任务
 */
@Slf4j
@Component("orderReplyTask")
public class OrderReplyTask implements ITask{

    private static final String LOCK_NAME = "order_reply_task";

    @Autowired
    private TbWorkOrderReplyService tbWorkOrderReplyService;

    @Autowired
    private RedisLockRegistry redisLockRegistry;

    @Override
    public void run(String params) {
        Lock lock = redisLockRegistry.obtain(LOCK_NAME);
        boolean isLock = lock.tryLock();
        if (isLock) {
            try {
                log.info("扫描工单附件:开始time:{}", DateUtil.date());
                tbWorkOrderReplyService.replyOrderService();
                log.info("扫描工单附件:结束time:{}", DateUtil.date());
            } finally {
                lock.unlock();
            }
        }
    }
}
